home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / common / util / messageStats.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  7.8 KB  |  262 lines

  1. /*
  2.  *   $RCSfile: messageStats.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:12 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include <stdio.h>
  39. #include <errno.h>
  40. #include "ess.h"
  41. #include "msgstats.h"
  42. #include "lsn.h"
  43. #include "io.h"
  44. #include "msgdefs.h"
  45.  
  46. MESSAGESTATS MsgStats;
  47. extern MESSAGENAME    MsgNames[];
  48.  
  49. MESSAGENAME MsgNames[] = {
  50.     {    NULL,                      /* unused */        0},
  51.     {    "MountVolume",                                  1},
  52.     {    "DismountVolume",                              2},
  53.     {    "FormatVolume",                                  3},
  54.     {    "ReadPage",                                      4},
  55.     {    "WritePage",                                  5},
  56.     {    "AllocPages",                                  6},
  57.     {    "DeallocPages",                                  7},
  58.     {    "CheckBitmap",                                  8},
  59.     {    "GetUnique",                                  9},
  60.     {    "StatVolume",                                 10},
  61.     {    "SetRootEntry",                                 11},
  62.     {    "GetRootEntry",                                 12},
  63.     {    NULL,                     /*unused*/         13},
  64.     {    "ExternalBegin",                             14},
  65.     {    "ExternalCommit",                             15},
  66.     {    "ExternalAbort",                             16},
  67.     {    "LockPage",                                     17},
  68.     {    "LockFile",                                     18},
  69.     {    "CreateFile",                                 19},
  70.     {    "DestroyFile",                                 20},
  71.     {    "FirstPhysicalPage",                         21},
  72.     {    "LastPhysicalPage",                             22},
  73.     {    "NeighborPage",                                 23},
  74.     {    "FirstLogicalPage",                          24},
  75.     {    "LastLogicalPage",                              25},
  76.     {    "MarkPage",                                     26},
  77.     {    "ResetRusage",                                 27},
  78.     {    "GetRusage",                                 28},
  79.     {    "CreateSequentialFile",                         29},
  80.     {    "OpenSequentialLoad",                         30},
  81.     {    "OpenSequentialScan",                         31},
  82.     {    "ScanNextSequential",                         32},
  83.     {    "LoadNextSequential",                         33},
  84.     {    "CloseResource",                             34},
  85.     {    "TestNullRpc",                                 35},
  86.     {    "TestPageRpc",                                 36},
  87.     {    "WriteLogPage",                                 37},
  88.     {    "InitClient",                                 38},
  89.     {    "UnlockPage",                                 39},
  90.     {    "UnlockFile",                                 40},
  91.     {    "QueryPage",                                 41},
  92.     {    "SetAnchor",                                 42},
  93.     {    "SetCLR",                                        43},
  94.     {    "MonDump",                                        44},
  95.     {    "TakeCheckpoint",                                45},
  96.     {    "ChangeCheckpointFreq",                            46},
  97.     {    "ShutServer",                                 47},
  98.     {    "Statistics",                                 48},
  99.     {    "DebugSetVar",                                 49},
  100.     {    "TestPageSend",                                 50},
  101.     {    "SyncTransaction",                             51},
  102.        {    "FileNumPages",                                 52},
  103.     {    "Enter2PC",                                       53},
  104.     {    "ClientPrepare",                             54},
  105.     {    "CoordPrepare",                                 55},
  106.     {    "Vote",                                           56},
  107.     {    "ClientDecision",                             57},
  108.     {    "Continue2PC",                                  58},
  109.     {    "Recover2PC",                                  59},
  110.     {    "CoordDecision",                              60},
  111.     {    "ServerAck",                                 61},
  112.     {    "AddVolume",                                  62},
  113.     {    "RemoveVolume",                                  63}
  114.  
  115. };
  116.  
  117. static int msglen = 19;
  118. static int mnumlen = 3;
  119. static int sumlen =  9;
  120. static char *labelslashformat = "%*.*s/%-*.*s: %*.*s %*.*s %*.*s %*.*s %*.*s\n";
  121. static char *labelformat = "%*.*s %-*.*s: %*.*s %*.*s %*.*s %*.*s %*.*s\n";
  122. static char *numformat = "%*.*s/%-*d: %*d %*d %*d %*d %*d\n";
  123. static char *total1format = "%*.*s : %*d %*d %*d %*d %*d\n";
  124. static char *sentrcvformat = "%*.*s : %*d %*d \n";
  125. static char *underscores = "___________________________________________________";
  126.  
  127. void
  128. printMessageStats( 
  129.     FILE *const f,
  130.     MESSAGESTATS *const msgStats
  131. )
  132.     register int i,
  133.         sent=0, received=0, replied_ok=0,
  134.         replied_in_error=0, no_reply_requested=0;
  135.     BOOL    first = TRUE;
  136.  
  137. #define ANY(j)\
  138.     ((msgStats->received[j] + MsgStats.sent[j] +\
  139.     msgStats->no_reply_requested[j] +\
  140.     msgStats->replied_in_error[j] + MsgStats.replied_ok[j]) > 0)
  141.  
  142.     for( i=0; i <= MAX_MSG_NUMBER; i++) {
  143.         if( ANY(i) ) {
  144.             if(first) {
  145.                 fprintf(f,"MESSAGE ACTIVITY:\n");
  146.                 fprintf(f, labelslashformat,
  147.                     msglen, msglen,   "MESSAGE",             
  148.                     mnumlen, mnumlen, "#", 
  149.                     sumlen, sumlen,   "SENT",     
  150.                     sumlen, sumlen,   "RECEIVED",  
  151.                     sumlen, sumlen,     "", 
  152.                     sumlen, sumlen,    "REPLIES",  
  153.                     sumlen, sumlen,     "");
  154.  
  155.                 fprintf(f, labelformat,
  156.                     msglen, msglen,   "",             
  157.                     mnumlen, mnumlen, "", 
  158.                     sumlen, sumlen,   "",     
  159.                     sumlen, sumlen,   "",  
  160.                     sumlen, sumlen,     "no reply", 
  161.                     sumlen, sumlen,    "in error",  
  162.                     sumlen, sumlen,     "OK");
  163.  
  164.                 fprintf(f, labelformat,
  165.                     msglen, msglen, underscores,
  166.                     mnumlen,mnumlen,underscores,
  167.                     sumlen, sumlen, underscores,
  168.                     sumlen, sumlen, underscores,
  169.                     sumlen, sumlen, underscores,
  170.                     sumlen, sumlen, underscores,
  171.                     sumlen, sumlen, underscores);
  172.                 first = FALSE;
  173.             }
  174.  
  175.             fprintf(f, numformat,
  176.                     msglen, msglen,   MsgNames[i].name, 
  177.                     mnumlen, i, 
  178.                     sumlen,   msgStats->sent[i],
  179.                     sumlen,   msgStats->received[i],
  180.                     sumlen,   msgStats->no_reply_requested[i],
  181.                     sumlen,   msgStats->replied_in_error[i],
  182.                     sumlen,   msgStats->replied_ok[i]);
  183.  
  184.             sent += msgStats->sent[i];
  185.             received += msgStats->received[i];
  186.             no_reply_requested += msgStats->no_reply_requested[i];
  187.             replied_in_error += msgStats->replied_in_error[i];
  188.             replied_ok += msgStats->replied_ok[i];
  189.         }
  190.     }
  191.     if(first) {
  192.         fprintf(f,"NO MESSAGE ACTIVITY.\n");
  193.     } else {
  194.         
  195.         fprintf(f, labelformat,
  196.                     msglen, msglen, underscores,
  197.                     mnumlen,mnumlen,underscores,
  198.                     sumlen, sumlen, underscores,
  199.                     sumlen, sumlen, underscores,
  200.                     sumlen, sumlen, underscores,
  201.                     sumlen, sumlen, underscores,
  202.                     sumlen, sumlen, underscores);
  203.         fprintf(f, total1format,
  204.                     msglen+mnumlen, msglen+mnumlen, "Total", 
  205.                     sumlen,     sent, 
  206.                     sumlen,     received, 
  207.                     sumlen,     no_reply_requested, 
  208.                     sumlen,     replied_in_error, 
  209.                     sumlen,     replied_ok);
  210.         fprintf(f, sentrcvformat,
  211.                     msglen+mnumlen, msglen+mnumlen, "Total bytes", 
  212.                     sumlen,  msgStats->bytes_sent, 
  213.                     sumlen,  msgStats->bytes_received);
  214.         fprintf(f, sentrcvformat,
  215.                     msglen+mnumlen, msglen+mnumlen, "Full page equiv",  
  216.                     sumlen,  msgStats->pages_sent, 
  217.                     sumlen,  msgStats->pages_received);
  218.         fprintf(f, sentrcvformat,
  219.                     msglen+mnumlen, msglen+mnumlen, "Partial page equiv",  
  220.                     sumlen,  msgStats->partial_pages_sent, 
  221.                     sumlen,  msgStats->partial_pages_received);
  222.     }
  223. }
  224.  
  225. void
  226. incPages(int totalBytes, int direction, BOOL includesMessage)
  227. {
  228.     int *sum, *partial;
  229.     int extra, pages;
  230.     
  231.     switch(direction) {
  232.     case SENT:
  233.         MsgStats.bytes_sent += totalBytes;
  234.         sum = &MsgStats.pages_sent;
  235.         partial = &MsgStats.partial_pages_sent;
  236.         break;
  237.  
  238.     case RECEIVED:
  239.         MsgStats.bytes_received += totalBytes;
  240.         sum = &MsgStats.pages_received;
  241.         partial = &MsgStats.partial_pages_received;
  242.         break;
  243.  
  244.     default:
  245.         /* SM_ERROR(TYPE_FATAL, esmINTERNAL); */
  246.         break;
  247.     }
  248.  
  249.     if(includesMessage) {
  250.         extra = totalBytes - sizeof(MESSAGE);
  251.     } else {
  252.         extra = totalBytes;
  253.     }
  254.  
  255.  
  256.     (*sum) += (pages = (extra / MIN_PAGESIZE));
  257.     if( (pages * MIN_PAGESIZE) < extra )  {
  258.         (*partial) ++;
  259.     }
  260. }
  261.